package com.justnow.dp;

/**
 * @author justnow
 * Created on 2020-10-04
 * Description
 */
public class Leetcode1143 {
    public static int longestCommonSubsequence(String text1, String text2) {
        int length1 = text1.length();
        int length2 = text2.length();
        int[][] dp = new int[length1 + 1][length2 + 1];
        char[] array1 = text1.toCharArray();
        char[] array2 = text2.toCharArray();
        // 记住此时的序号问题
        for (int i = 1; i <= length1; i++) {
            for (int j = 1; j <= length2; j++) {
                if (array1[i - 1] == array2[j - 1]) {
                    dp[i][j] = dp[i-1][j-1] + 1;
                } else {
                    dp[i][j] = Math.max(dp[i-1][j], dp[i][j-1]);
                }
            }
        }
        return dp[length1][length2];
    }

    public static void main(String[] args) {
        int i = longestCommonSubsequence("abcde", "ace");
        System.out.println(i);
    }
}
